package utils

import (
	"github.com/golang-module/carbon"
	"regexp"
	"time"
)

// TimestampToString 时间转时间戳
func TimestampToString(date time.Time) int64 {
	return date.UnixNano() / 1e6
}

// CheckGbTime 判断时间格式
func CheckGbTime(timeStr string) bool {
	regex := regexp.MustCompile(`^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})-(\d{2}:(\d{2}))$`)
	return regex.MatchString(timeStr)
}

func DateTimeStrToTime(dateTimeStr string) time.Time {
	//carbon.SetLocale("zh")
	//carbon.SetTimezone(time.FixedZone("Asia/Shanghai", 8*3600).String())
	return carbon.Parse(dateTimeStr).Carbon2Time()
}

func DateStrToTime(dateTimeStr string) time.Time {
	local, _ := time.LoadLocation("Asia/Shanghai")
	dateTime, _ := time.ParseInLocation("2006-01-02", dateTimeStr, local)
	return dateTime
}
